package com.malie.myspringboot.easypoi;

import java.util.ArrayList;
import java.util.Date;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.compress.utils.Lists;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class Test {

    /**
     * 要表头
     * @param response
     */
    @GetMapping("export")
    public void exportDemo(HttpServletResponse response){
        ImportAndExportEntity entity = new ImportAndExportEntity();
        entity.setName("huang");
        entity.setCreateTime(new Date());
        entity.setState("1");
        ArrayList<ImportAndExportEntity> list = Lists.newArrayList();
        list.add(entity);
        EasyPoiUtil.exportExcel(list,"demo","sheet1",ImportAndExportEntity.class,"测试",true,response);

    }

    /**
     * 不要表头
     * @param response
     */
    @GetMapping("export1")
    public void exportDemo1(HttpServletResponse response){
        ImportAndExportEntity entity = new ImportAndExportEntity();
        entity.setName("huang");
        entity.setCreateTime(new Date());
        entity.setState("1");
        ArrayList<ImportAndExportEntity> list = Lists.newArrayList();
        list.add(entity);
        EasyPoiUtil.exportExcel(list,"demo","sheet1",ImportAndExportEntity.class,"测试",response);

    }

}
